package com.easy.admin.system.controller;

import cn.hutool.core.swing.clipboard.ClipboardUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.easy.admin.system.annon.FormToken;
import com.easy.admin.system.comnon.HttpClient;
import com.wf.captcha.ArithmeticCaptcha;
import com.wf.captcha.utils.CaptchaUtil;
import org.apache.ibatis.annotations.Param;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RequestMapping("/user")
@Controller
public class UserController {

    @RequestMapping("/update")
    @ResponseBody
    public Object update(@Param("file") MultipartFile file,String content){
        System.out.println(file.getOriginalFilename());
        return true;
    }

    @RequestMapping("/vueTest")
    public String vueTest(){
        return "vue/VueTest";
    }

    @RequestMapping("ajaxTestData")
    @ResponseBody
    @FormToken(saveToken = true,name="login")
    public Object ajaxTestData(){
        Map hqash = new HashMap();
        hqash.put("name","张三");
        hqash.put("sex",1);
        Map hqash1 = new HashMap();
        hqash1.put("name","李四");
        hqash1.put("sex",2);
        List list  = new ArrayList<>();
        list.add(hqash);
        list.add(hqash1);
        return list;
    }

    @RequestMapping("/login")
    @ResponseBody
    public Object login(String account,String password){
        if(account.equals(password)){
            return account;
        }
        return null;
    }

    @RequestMapping("/map")
    public Object map(){
        return "/map/map";
    }

    @RequestMapping("/getAllNews")
    @ResponseBody
    public Object getAllNews(){
       Map<String,Object> map1 = new HashMap<>();
       map1.put("title","许巍演唱会近期在西安举行");
       map1.put("date","2019-12-03");
       map1.put("img","https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1575351441296&di=fb77b3747525c7c834015187f6be2997&imgtype=0&src=http%3A%2F%2Fr.sinaimg.cn%2Flarge%2Ftc%2Fmmbiz_qpic_cn%2Faa5e29ea29eb5baf2b2e9bdcd6e20c3e.jpg");
       map1.put("desc","现场用西安方言和粉丝互动，场面极其热烈,现场演唱了了《蓝莲花》《曾经的你》等经典歌曲");

        Map<String,Object> map2 = new HashMap<>();
        map2.put("title","李志2015相信未来演唱会在南京举行");
        map2.put("date","2019-12-03");
        map2.put("img","https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=3476882232,2088184414&fm=26&gp=0.jpg");
        map2.put("desc","关于郑州，我知道的只有你，我在南京等你");

        Map<String,Object> map3 = new HashMap<>();
        map3.put("title","赵雷新曲发布《南方姑娘》");
        map3.put("date","2019-12-05");
        map3.put("img","https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1575351579565&di=207bc554280957f3f7609f8fa9b053e6&imgtype=0&src=http%3A%2F%2Fn.sinaimg.cn%2Fsinacn11%2F688%2Fw1000h488%2F20180417%2F0cd2-fzihnen8460683.jpg");
        map3.put("desc","他是一个热爱音乐的青年，他说过，有些人是不得不做音乐，而他是必须要做音乐，他就是民谣小伙赵雷");
       List<Map<String,Object>> lsit  = new ArrayList<>();
       lsit.add(map1);
       lsit.add(map2);
        lsit.add(map3);
        return lsit;
    }


    @RequestMapping("/getNewsMusicList")
    @ResponseBody
    public Object getNewsMusicList(){
        Map<String,Object> map1 = new HashMap<>();
        map1.put("poster","https://ss0.bdstatic.com/6Ox1bjeh1BF3odCf/it/u=2139432625,1803119984&fm=74&app=80&f=JPEG&size=f121,121?sec=1880279984&t=580ff2513dc01cc09b708fe5f300d0dd");//头像
        map1.put("name","起风了");//名称
        map1.put("author","买辣椒也用券");//作者
        map1.put("src","http://sc1.111ttt.cn/2018/1/03/13/396131213056.mp3");//链接

        Map<String,Object> map2 = new HashMap<>();
        map2.put("poster","https://ss0.baidu.com/6ONWsjip0QIZ8tyhnq/it/u=493048239,3947894831&fm=179&app=42&f=JPEG?w=121&h=140");//头像
        map2.put("name","广东爱情故事");//名称
        map2.put("author","广东雨神");//作者
        map2.put("src","http://sc1.111ttt.cn/2018/1/03/13/396131203208.mp3");//链接

        Map<String,Object> map3 = new HashMap<>();
        map3.put("poster","https://ss1.bdstatic.com/6OF1bjeh1BF3odCf/it/u=3601429989,3371662466&fm=74&app=80&f=JPEG&size=f121,140?sec=1880279984&t=0d9e14654bcc85fa31f69cacec8de3fe");//头像
        map3.put("name","我和我的祖国");//名称
        map3.put("author","平安");//作者
        map3.put("src","http://sc1.111ttt.cn/2016/1/12/10/205101007238.mp3");//链接
        List<Map<String,Object>> lsit  = new ArrayList<>();
        lsit.add(map1);
        lsit.add(map2);
        lsit.add(map3);
        return lsit;
    }



    @RequestMapping("/getMusic")
    public void getMusic(HttpServletResponse response) throws Exception{
        FileOutputStream out = new FileOutputStream(new File("D:\\LiBB\\无损\\勾三搭四\\离婚.flac"));
       // response.getOutputStream().wri
    }

    @RequestMapping("/WxMiniProLogin")
    @ResponseBody
    public Object WxMiniProLogin(String code){
        try {
            HttpClient cil = new HttpClient("https://api.weixin.qq.com/sns/jscode2session?appid=wx5cfd4ec4f6ba4fde&secret=8040a49a72030e9023346b5e14452434&js_code="+code+"&grant_type=authorization_code");
            cil.get();
            String content = cil.getContent();
            System.out.println(content);
            return content;
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }

    @RequestMapping("/getVerifyCode")
    @RequiresPermissions(value = "user:getVerifyCode")
    public void getVerifyCode(HttpServletRequest request,HttpServletResponse response) throws Exception {
        ArithmeticCaptcha arithmeticCaptcha = new ArithmeticCaptcha();
        arithmeticCaptcha.setLen(2);
        arithmeticCaptcha.setHeight(130);
        arithmeticCaptcha.setWidth(80);
        String lm = arithmeticCaptcha.getArithmeticString();
        String result = arithmeticCaptcha.text();
        System.out.println(lm.substring(0,lm.length()-1)+result);
        CaptchaUtil.out(arithmeticCaptcha,request,response);
    }

    @RequestMapping("/copy")
    @ResponseBody
    public Object copy(String value){
       /* try {
            ClipboardUtil.setStr(value);
            return "true";
        }catch(Exception e){
            return e.getMessage();
        }*/
        System.out.println(value);
       ClipboardUtil.setStr("121212");
       return true;
    }

}
